/*
 * table_MemoryDebugInfo.c
 *
 *  Created on: 2012/05/16
 *      Author: guanxiaoying
 */
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include "typedef.h"
#include "Id.h"
#include "lib_func.h"
#include "core.h"
#include "encode.h"
#include "./textfile/pf_file.h"
#include "./memory/mem_interface.h"
#include "./table.h"

typedef struct _MEMORY_DEBUG
{
	TABLEMANAGER * manager;
	U2  lineno;
	U2  errcode;
	AST  astMax;
	AST  astIdx;
} MEMORY_DEBUG, *PMEMORY_DEBUG;

#define TableSize  (sizeof(MEMORY_DEBUG ))
#define TableType  PMEMORY_DEBUG
#define stTable stDebugInfoManager.memoryBlocks
#define maxTable stDebugInfoManager.maxRecordNum
#define  maxNumPerBlk  (stDebugInfoManager.astMaxNum_Block)

static TABLEMANAGER stDebugInfoManager = {
//		U4                  usIdx;
		0,
//		PSZ				    con_pszName;    constant
		__FILE__,
//		U2					con_usSize;		constant
		TableSize,
//		U2					block_num;	　　　　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_Block;     １回設定のみ
		0,
//		S4					astTabNum_LastPage; 　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_LastPage;     Reset clear  際　要
		0,
//		U4					ulMaxByte;	　　　　　　　　　　クリアしない
		0,
//		U4					con_minPageSize;　　　　　　　　　　constant
		0
};
static VOID resetListener( U4  procid, U2 index )
{
	if( procid == stDebugInfoManager.u4Idx )
	{
		if( index > 0 && index < MAX_VOLUMN_OF_TABLE )
		{
			stTable[ index-1] = NULL;
		}
	}
}
static TableType core_getTable( AST index )
{
	TableType temp = (TableType)Check_Com( &stDebugInfoManager, resetListener,  index );
	if( temp != NULL ){ return &temp[index%maxNumPerBlk]; } return NULL;
}
static BOOL ClearTable( VOID )
{
	return Clear_Com( &stDebugInfoManager );
}
static BOOL AllocTable( AST astReqArg )
{
	return AllocTable_Com( &stDebugInfoManager, astReqArg, resetListener );
}
static AST getMaxLineNum( VOID ){
	return maxTable;
}
/* give up the way that defining get/set function pointer in the struct,
 * because of memory volume.
 */
//	USHORT_OBJKIND
static TABLEMANAGER*  getTbl( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->manager;
}
/* set method */
static AST  setTbl( AST index, TABLEMANAGER* value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	pTbl->manager = value;
	return index;
}
static U4  getLineNo( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->lineno;
}
/* set method */
static U4  setLineNo( AST index, U4 value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->lineno = value;
}
static U2  getErrorCode( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->errcode;
}
/* set method */
static U2 setErrorCode( AST index, U2 value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->errcode = value;
}
static AST  getMax( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astMax;
}
/* set method */
static AST setMax( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astMax = value;
}
static AST  getIdx( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astIdx;
}
/* set method */
static AST setIdx( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astIdx = value;
}
const MEMORYDEBUGINFO_ACCESS stMemoryDebugInfoAccess = {

				ClearTable,
				AllocTable,
				getMaxLineNum,

				getTbl,
				setTbl,

				{
						getLineNo,
						setLineNo
				},
				{
						getErrorCode,
						setErrorCode
				},
				{
						getMax,
						setMax
				},
				{
						getIdx,
						setIdx
				}
};
/* end of file */

